﻿Imports System.Windows.Forms
Imports Microsoft.VisualBasic.ControlChars
Imports System.IO
Imports DISMTools.Utilities

Public Class RemProvAppxPackage
    Implements IImageTaskDialog

    Public AppxRemovalPackages(65535) As String
    Public AppxRemovalFriendlyNames(65535) As String
    Public AppxRemovalCount As Integer

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        DynaLog.LogMessage("Disposing of progress panel if not disposed of previously...")
        If Not ProgressPanel.IsDisposed Then ProgressPanel.Dispose()
        AppxRemovalCount = ListView1.CheckedItems.Count
        ProgressPanel.appxRemovalCount = AppxRemovalCount
        DynaLog.LogMessage("Detecting AppX packages to remove...")
        If ListView1.CheckedItems.Count = 0 Then
            DynaLog.LogMessage("No items have been selected for removal.")
            Select Case MainForm.Language
                Case 0
                    Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
                        Case "ENU", "ENG"
                            MsgBox("Please specify AppX packages to remove and try again.", vbOKOnly + vbCritical, "Remove provisioned AppX packages")
                        Case "ESN"
                            MsgBox("Especifique paquetes AppX a eliminar e inténtelo de nuevo.", vbOKOnly + vbCritical, "Eliminar paquetes aprovisionados AppX")
                        Case "FRA"
                            MsgBox("Veuillez indiquer les paquets AppX à supprimer et réessayer.", vbOKOnly + vbCritical, "Supprimer les paquets AppX provisionnés")
                        Case "PTB", "PTG"
                            MsgBox("Especifique os pacotes AppX a remover e tente novamente.", vbOKOnly + vbCritical, "Remover pacotes AppX aprovisionados")
                        Case "ITA"
                            MsgBox("Specificare i pacchetti AppX da rimuovere e riprovare", vbOKOnly + vbCritical, "Rimuovere i pacchetti AppX in dotazione")
                    End Select
                Case 1
                    MsgBox("Please specify AppX packages to remove and try again.", vbOKOnly + vbCritical, "Remove provisioned AppX packages")
                Case 2
                    MsgBox("Especifique paquetes AppX a eliminar e inténtelo de nuevo.", vbOKOnly + vbCritical, "Eliminar paquetes aprovisionados AppX")
                Case 3
                    MsgBox("Veuillez indiquer les paquets AppX à supprimer et réessayer.", vbOKOnly + vbCritical, "Supprimer les paquets AppX provisionnés")
                Case 4
                    MsgBox("Especifique os pacotes AppX a remover e tente novamente.", vbOKOnly + vbCritical, "Remover pacotes AppX aprovisionados")
                Case 5
                    MsgBox("Specificare i pacchetti AppX da rimuovere e riprovare", vbOKOnly + vbCritical, "Rimuovere i pacchetti AppX in dotazione")
            End Select
            Exit Sub
        Else
            DynaLog.LogMessage("AppX packages to remove: " & AppxRemovalCount)
            If AppxRemovalCount > 65535 Then
                MsgBox("Right now, you can only specify less than 65535 AppX packages. This is a program limitation that will be gone in a future update.", vbOKOnly + vbCritical, "Remove provisioned AppX packages")
                Exit Sub
            Else
                DynaLog.LogMessage("Adding AppX packages to queue...")
                For x = 0 To AppxRemovalCount - 1
                    AppxRemovalPackages(x) = ListView1.CheckedItems(x).Text
                Next
                For x = 0 To AppxRemovalCount - 1
                    AppxRemovalFriendlyNames(x) = ListView1.CheckedItems(x).SubItems(1).Text
                Next
                For x = 0 To AppxRemovalPackages.Length - 1
                    ProgressPanel.appxRemovalPackages(x) = AppxRemovalPackages(x)
                Next
                For x = 0 To AppxRemovalFriendlyNames.Length - 1
                    ProgressPanel.appxRemovalPkgNames(x) = AppxRemovalFriendlyNames(x)
                Next
                ProgressPanel.appxRemovalLastPackage = ListView1.CheckedItems(AppxRemovalCount - 1).ToString().Replace("ListViewItem: {", "").Trim().Replace("}", "").Trim()

                ' If the image contains a Server Core/Nano Server installation, detect whether the Desktop Experience
                ' feature is installed
                DynaLog.LogMessage("Detecting conditions imposed by the Windows image...")
                If MainForm.imgInstType <> "" And (MainForm.imgInstType.Contains("Nano") Or MainForm.imgInstType.Contains("Core")) Then
                    DynaLog.LogMessage("Target Windows image contains Server Core SKU. Detecting state of Desktop Experience feature...")
                    ' Go through every feature and find Desktop Experience
                    If MainForm.imgFeatureNames.Count > 0 Then
                        For x = 0 To Array.LastIndexOf(MainForm.imgFeatureNames, MainForm.imgFeatureNames.Last)
                            If MainForm.imgFeatureNames(x) = "DesktopExperience" Then
                                ' Detect the state of the feature
                                If MainForm.imgFeatureState(x) <> "Enabled" Then
                                    DynaLog.LogMessage("Desktop Experience has been detected as a disabled feature.")
                                    Dim msg As String = ""
                                    ' Display incompatibility
                                    Select Case MainForm.Language
                                        Case 0
                                            Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
                                                Case "ENU", "ENG"
                                                    msg = "The Desktop Experience (DesktopExperience) feature needs to be enabled in order to remove AppX packages in Windows Server Core/Nano Server images." & CrLf & CrLf & "Enable this feature, boot to the image, and try again."
                                                Case "ESN"
                                                    msg = "La característica Experiencia del Escritorio (DesktopExperience) debe estar habilitada para eliminar paquetes AppX en imágenes Windows Server Core/Nano Server." & CrLf & CrLf & "Habilite esta característica, arranque la imagen, e inténtelo de nuevo."
                                                Case "FRA"
                                                    msg = "La caractéristique Expérience du bureau (DesktopExperience) doit être activée afin de supprimer les paquets AppX dans les images Windows Server Core/Nano Server." & CrLf & CrLf & "Activez cette caractéristique, démarrez sur l'image et réessayez."
                                                Case "PTB", "PTG"
                                                    msg = "A caraterística Área de Trabalho (DesktopExperience) tem de ser ativada para remover pacotes AppX nas imagens do Windows Server Core/Nano Server." & CrLf & CrLf & "Ative esta caraterística, arranque para a imagem e tente novamente."
                                                Case "ITA"
                                                    msg = "Le caratteristiche di Esperienza del Desktop (DesktopExperience) devono essere abilitate per rimuovere i pacchetti AppX nelle immagini di Windows Server Core/Nano Server." & CrLf & CrLf & "Abilitate questa caratteristica, avviate l'immagine e riprovate"
                                            End Select
                                        Case 1
                                            msg = "The Desktop Experience (DesktopExperience) feature needs to be enabled in order to remove AppX packages in Windows Server Core/Nano Server images." & CrLf & CrLf & "Enable this feature, boot to the image, and try again."
                                        Case 2
                                            msg = "La característica Experiencia del Escritorio (DesktopExperience) debe estar habilitada para eliminar paquetes AppX en imágenes Windows Server Core/Nano Server." & CrLf & CrLf & "Habilite esta característica, arranque la imagen, e inténtelo de nuevo."
                                        Case 3
                                            msg = "La caractéristique Expérience du bureau (DesktopExperience) doit être activée afin de supprimer les paquets AppX dans les images Windows Server Core/Nano Server." & CrLf & CrLf & "Activez cette caractéristique, démarrez sur l'image et réessayez."
                                        Case 4
                                            msg = "A caraterística Área de Trabalho (DesktopExperience) tem de ser ativada para remover pacotes AppX nas imagens do Windows Server Core/Nano Server." & CrLf & CrLf & "Ative esta caraterística, arranque para a imagem e tente novamente."
                                        Case 5
                                            msg = "Le caratteristiche di Esperienza del Desktop (DesktopExperience) devono essere abilitate per rimuovere i pacchetti AppX nelle immagini di Windows Server Core/Nano Server." & CrLf & CrLf & "Abilitate questa caratteristica, avviate l'immagine e riprovate"
                                    End Select
                                    MsgBox(msg, vbOKOnly + vbCritical, Label1.Text)
                                    Exit Sub
                                End If
                            End If
                        Next
                    End If
                End If
            End If
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        ProgressPanel.OperationNum = 38
        Visible = False
        ProgressPanel.ShowDialog(MainForm)
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Function Initialize() As Boolean Implements IImageTaskDialog.Initialize
        DynaLog.LogMessage("Checking edition and version information for any unmet requirements...")
        If MainForm.imgEdition.Equals("WindowsPE", StringComparison.OrdinalIgnoreCase) Or Not MainForm.IsWindows8OrHigher(MainForm.MountDir & "\Windows\system32\ntoskrnl.exe") Then
            DynaLog.LogMessage("The image is not supported")
            Select Case MainForm.Language
                Case 0
                    Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
                        Case "ENU", "ENG"
                            MsgBox("This action is not supported on this image", vbOKOnly + vbCritical, Text)
                        Case "ESN"
                            MsgBox("Esta acción no está soportada en esta imagen", vbOKOnly + vbCritical, Text)
                        Case "FRA"
                            MsgBox("Cette action n'est pas prise en charge sur cette image", vbOKOnly + vbCritical, Text)
                        Case "PTB", "PTG"
                            MsgBox("Esta ação não é suportada nesta imagem", vbOKOnly + vbCritical, Text)
                        Case "ITA"
                            MsgBox("Questa azione non è supportata su questa immagine", vbOKOnly + vbCritical, Text)
                    End Select
                Case 1
                    MsgBox("This action is not supported on this image", vbOKOnly + vbCritical, Text)
                Case 2
                    MsgBox("Esta acción no está soportada en esta imagen", vbOKOnly + vbCritical, Text)
                Case 3
                    MsgBox("Cette action n'est pas prise en charge sur cette image", vbOKOnly + vbCritical, Text)
                Case 4
                    MsgBox("Esta ação não é suportada nesta imagem", vbOKOnly + vbCritical, Text)
                Case 5
                    MsgBox("Questa azione non è supportata su questa immagine", vbOKOnly + vbCritical, Text)
            End Select
            Return False
        End If
        DynaLog.LogMessage("All requirements are met. Continuing with the task...")
        ListView1.Items.Clear()
        If Not MainForm.CompletedTasks(2) Then
            DynaLog.LogMessage("AppX package background processes haven't completed.")
            BGProcsBusyDialog.ShowDialog(Me)
            Return False
        End If
        DynaLog.LogMessage("Adding AppX packages to arrays...")
        If MainForm.imgAppxPackageNames.Count > MainForm.imgAppxPackages.Count Then
            Try
                For x = 0 To Array.LastIndexOf(MainForm.imgAppxPackageNames, MainForm.imgAppxPackageNames.Last)
                    If MainForm.imgAppxPackageNames(x) = "" Or MainForm.imgAppxPackageNames(x) = "Nothing" Then
                        Continue For
                    Else
                        If Directory.Exists(MainForm.MountDir & "\ProgramData\Microsoft\Windows\AppRepository\Packages\" & MainForm.imgAppxPackageNames(x)) Then
                            If My.Computer.FileSystem.GetFiles(MainForm.MountDir & "\ProgramData\Microsoft\Windows\AppRepository\Packages\" & MainForm.imgAppxPackageNames(x), FileIO.SearchOption.SearchTopLevelOnly, "*.pckgdep").Count = 0 Then
                                ListView1.Items.Add(New ListViewItem(New String() {MainForm.imgAppxPackageNames(x), MainForm.imgAppxDisplayNames(x), MainForm.imgAppxArchitectures(x), MainForm.imgAppxResourceIds(x), MainForm.imgAppxVersions(x), "No"}))
                            Else
                                ListView1.Items.Add(New ListViewItem(New String() {MainForm.imgAppxPackageNames(x), MainForm.imgAppxDisplayNames(x), MainForm.imgAppxArchitectures(x), MainForm.imgAppxResourceIds(x), MainForm.imgAppxVersions(x), "Yes"}))
                            End If
                        Else
                            ListView1.Items.Add(New ListViewItem(New String() {MainForm.imgAppxPackageNames(x), MainForm.imgAppxDisplayNames(x), MainForm.imgAppxArchitectures(x), MainForm.imgAppxResourceIds(x), MainForm.imgAppxVersions(x), "No"}))
                        End If
                    End If
                Next
            Catch ex As Exception
                ' We should have enough with the entries already added.
            End Try
        Else
            For Each imgAppxPackage In MainForm.imgAppxPackages
                Dim isRegistered As Boolean
                If Directory.Exists(MainForm.MountDir & "\ProgramData\Microsoft\Windows\AppRepository\Packages\" & imgAppxPackage.PackageName) Then
                    If My.Computer.FileSystem.GetFiles(MainForm.MountDir & "\ProgramData\Microsoft\Windows\AppRepository\Packages\" & imgAppxPackage.PackageName, FileIO.SearchOption.SearchTopLevelOnly, "*.pckgdep").Count = 0 Then
                        isRegistered = False
                    Else
                        isRegistered = True
                    End If
                Else
                    isRegistered = False
                End If
                ListView1.Items.Add(New ListViewItem(New String() {imgAppxPackage.PackageName, imgAppxPackage.DisplayName, Casters.CastDismArchitecture(imgAppxPackage.Architecture), imgAppxPackage.ResourceId, imgAppxPackage.Version.ToString(), If(isRegistered, "Yes", "No")}))
            Next
        End If
        Return True
    End Function

    Private Sub RemProvAppxPackage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not Initialize() Then
            Close()
        End If
        Select Case MainForm.Language
            Case 0
                Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
                    Case "ENU", "ENG"
                        Text = "Remove provisioned AppX packages"
                        Label1.Text = Text
                        Label3.Text = "If an application is registered to a user, you will need to run this PowerShell command in order to completely remove it:"
                        Label4.Text = "Remove-AppxPackage -Package <package name>"
                        Label5.Text = "Otherwise, the application will not be provisioned for new users. Check the " & Quote & "Registered to any user?" & Quote & " column for more details"
                        LinkLabel1.Text = "How does the program determine whether an application is registered to a user?"
                        OK_Button.Text = "OK"
                        Cancel_Button.Text = "Cancel"
                        ListView1.Columns(0).Text = "Package name"
                        ListView1.Columns(1).Text = "Application display name"
                        ListView1.Columns(2).Text = "Architecture"
                        ListView1.Columns(3).Text = "Resource ID"
                        ListView1.Columns(4).Text = "Version"
                        ListView1.Columns(5).Text = "Registered to any user?"
                    Case "ESN"
                        Text = "Eliminar paquetes aprovisionados AppX"
                        Label1.Text = Text
                        Label3.Text = "Si una aplicación está registrada a un usuario, debe ejecutar este comando de PowerShell para eliminarla completamente:"
                        Label4.Text = "Remove-AppxPackage -Package <nombre de paquete>"
                        Label5.Text = "Si no, la aplicación no será aprovisionada para nuevos usuarios. Compruebe la columna " & Quote & "¿Registrada a un usuario?" & Quote & " para más información"
                        LinkLabel1.Text = "¿Cómo determina el programa si una aplicación está registrada a un usuario?"
                        OK_Button.Text = "Aceptar"
                        Cancel_Button.Text = "Cancelar"
                        ListView1.Columns(0).Text = "Nombre de paquete"
                        ListView1.Columns(1).Text = "Nombre de aplicación"
                        ListView1.Columns(2).Text = "Arquitectura"
                        ListView1.Columns(3).Text = "ID de recursos"
                        ListView1.Columns(4).Text = "Versión"
                        ListView1.Columns(5).Text = "¿Registrada a un usuario?"
                    Case "FRA"
                        Text = "Supprimer les paquets AppX provisionnés"
                        Label1.Text = Text
                        Label3.Text = "Si une application est enregistrée auprès d'un utilisateur, vous devrez exécuter cette commande PowerShell afin de la supprimer complètement :"
                        Label4.Text = "Remove-AppxPackage -Package <nom du paquet>"
                        Label5.Text = "Dans le cas contraire, l'application ne sera pas approvisionnée pour les nouveaux utilisateurs. Pour plus de détails, consultez la colonne " & Quote & "Enregistré auprès d'un utilisateur ?" & Quote
                        LinkLabel1.Text = "Comment le programme détermine-t-il si une application est enregistrée auprès d'un utilisateur ?"
                        OK_Button.Text = "OK"
                        Cancel_Button.Text = "Annuler"
                        ListView1.Columns(0).Text = "Nom du paquet"
                        ListView1.Columns(1).Text = "Nom d'affichage de l'application"
                        ListView1.Columns(2).Text = "Architecture"
                        ListView1.Columns(3).Text = "ID de la ressource"
                        ListView1.Columns(4).Text = "Version"
                        ListView1.Columns(5).Text = "Enregistré au nom d'un utilisateur ?"
                    Case "PTB", "PTG"
                        Text = "Remover pacotes AppX provisionados"
                        Label1.Text = Text
                        Label3.Text = "Se um aplicativo estiver registrado para um usuário, você precisará executar este comando do PowerShell para removê-lo completamente:"
                        Label4.Text = "Remove-AppxPackage -Package <nome do pacote>"
                        Label5.Text = "Caso contrário, a aplicação não será aprovisionada para novos utilizadores. Consulte a coluna " & Quote & "Registado em qualquer utilizador?" & Quote & " para obter mais detalhes"
                        LinkLabel1.Text = "Como é que o programa determina se uma aplicação está registada para um utilizador?"
                        OK_Button.Text = "OK"
                        Cancel_Button.Text = "Cancelar"
                        ListView1.Columns(0).Text = "Nome do pacote"
                        ListView1.Columns(1).Text = "Nome de apresentação da aplicação"
                        ListView1.Columns(2).Text = "Arquitetura"
                        ListView1.Columns(3).Text = "ID do recurso"
                        ListView1.Columns(4).Text = "Versão"
                        ListView1.Columns(5).Text = "Registado por algum utilizador?"
                    Case "ITA"
                        Text = "Rimuovi i pacchetti AppX in provisioning"
                        Label1.Text = Text
                        Label3.Text = "Se un'applicazione è registrata per un utente, è necessario eseguire questo comando PowerShell per rimuoverla completamente:"
                        Label4.Text = "Remove-AppxPackage -Package <nome pacchetto>"
                        Label5.Text = "Altrimenti, l'applicazione non potrà essere fornita ai nuovi utenti. Controllare la colonna " & Quote & "Registrato a qualche utente?" & Quote & " per maggiori dettagli"
                        LinkLabel1.Text = "Come fa il programma a determinare se un'applicazione è registrata per un utente?"
                        OK_Button.Text = "OK"
                        Cancel_Button.Text = "Annullare"
                        ListView1.Columns(0).Text = "Nome del pacchetto"
                        ListView1.Columns(1).Text = "Nome del display dell'applicazione"
                        ListView1.Columns(2).Text = "Architettura"
                        ListView1.Columns(3).Text = "ID risorsa"
                        ListView1.Columns(4).Text = "Versione"
                        ListView1.Columns(5).Text = "Registrato a qualche utente?"
                End Select
            Case 1
                Text = "Remove provisioned AppX packages"
                Label1.Text = Text
                Label3.Text = "If an application is registered to a user, you will need to run this PowerShell command in order to completely remove it:"
                Label4.Text = "Remove-AppxPackage -Package <package name>"
                Label5.Text = "Otherwise, the application will not be provisioned for new users. Check the " & Quote & "Registered to any user?" & Quote & " column for more details"
                LinkLabel1.Text = "How does the program determine whether an application is registered to a user?"
                OK_Button.Text = "OK"
                Cancel_Button.Text = "Cancel"
                ListView1.Columns(0).Text = "Package name"
                ListView1.Columns(1).Text = "Application display name"
                ListView1.Columns(2).Text = "Architecture"
                ListView1.Columns(3).Text = "Resource ID"
                ListView1.Columns(4).Text = "Version"
                ListView1.Columns(5).Text = "Registered to any user?"
            Case 2
                Text = "Eliminar paquetes aprovisionados AppX"
                Label1.Text = Text
                Label3.Text = "Si una aplicación está registrada a un usuario, debe ejecutar este comando de PowerShell para eliminarla completamente:"
                Label4.Text = "Remove-AppxPackage -Package <nombre de paquete>"
                Label5.Text = "Si no, la aplicación no será aprovisionada para nuevos usuarios. Compruebe la columna " & Quote & "¿Registrada a un usuario?" & Quote & " para más información"
                LinkLabel1.Text = "¿Cómo determina el programa si una aplicación está registrada a un usuario?"
                OK_Button.Text = "Aceptar"
                Cancel_Button.Text = "Cancelar"
                ListView1.Columns(0).Text = "Nombre de paquete"
                ListView1.Columns(1).Text = "Nombre de aplicación"
                ListView1.Columns(2).Text = "Arquitectura"
                ListView1.Columns(3).Text = "ID de recursos"
                ListView1.Columns(4).Text = "Versión"
                ListView1.Columns(5).Text = "¿Registrada a un usuario?"
            Case 3
                Text = "Supprimer les paquets AppX provisionnés"
                Label1.Text = Text
                Label3.Text = "Si une application est enregistrée auprès d'un utilisateur, vous devrez exécuter cette commande PowerShell afin de la supprimer complètement :"
                Label4.Text = "Remove-AppxPackage -Package <nom du paquet>"
                Label5.Text = "Dans le cas contraire, l'application ne sera pas approvisionnée pour les nouveaux utilisateurs. Pour plus de détails, consultez la colonne " & Quote & "Enregistré auprès d'un utilisateur ?" & Quote
                LinkLabel1.Text = "Comment le programme détermine-t-il si une application est enregistrée auprès d'un utilisateur ?"
                OK_Button.Text = "OK"
                Cancel_Button.Text = "Annuler"
                ListView1.Columns(0).Text = "Nom du paquet"
                ListView1.Columns(1).Text = "Nom d'affichage de l'application"
                ListView1.Columns(2).Text = "Architecture"
                ListView1.Columns(3).Text = "ID de la ressource"
                ListView1.Columns(4).Text = "Version"
                ListView1.Columns(5).Text = "Enregistré au nom d'un utilisateur ?"
            Case 4
                Text = "Remover pacotes AppX provisionados"
                Label1.Text = Text
                Label3.Text = "Se um aplicativo estiver registrado para um usuário, você precisará executar este comando do PowerShell para removê-lo completamente:"
                Label4.Text = "Remove-AppxPackage -Package <nome do pacote>"
                Label5.Text = "Caso contrário, a aplicação não será aprovisionada para novos utilizadores. Consulte a coluna " & Quote & "Registado em qualquer utilizador?" & Quote & " para obter mais detalhes"
                LinkLabel1.Text = "Como é que o programa determina se uma aplicação está registada para um utilizador?"
                OK_Button.Text = "OK"
                Cancel_Button.Text = "Cancelar"
                ListView1.Columns(0).Text = "Nome do pacote"
                ListView1.Columns(1).Text = "Nome de apresentação da aplicação"
                ListView1.Columns(2).Text = "Arquitetura"
                ListView1.Columns(3).Text = "ID do recurso"
                ListView1.Columns(4).Text = "Versão"
                ListView1.Columns(5).Text = "Registado por algum utilizador?"
            Case 5
                Text = "Rimuovi i pacchetti AppX in provisioning"
                Label1.Text = Text
                Label3.Text = "Se un'applicazione è registrata per un utente, è necessario eseguire questo comando PowerShell per rimuoverla completamente:"
                Label4.Text = "Remove-AppxPackage -Package <nome pacchetto>"
                Label5.Text = "Altrimenti, l'applicazione non potrà essere fornita ai nuovi utenti. Controllare la colonna " & Quote & "Registrato a qualche utente?" & Quote & " per maggiori dettagli"
                LinkLabel1.Text = "Come fa il programma a determinare se un'applicazione è registrata per un utente?"
                OK_Button.Text = "OK"
                Cancel_Button.Text = "Annullare"
                ListView1.Columns(0).Text = "Nome del pacchetto"
                ListView1.Columns(1).Text = "Nome del display dell'applicazione"
                ListView1.Columns(2).Text = "Architettura"
                ListView1.Columns(3).Text = "ID risorsa"
                ListView1.Columns(4).Text = "Versione"
                ListView1.Columns(5).Text = "Registrato a qualche utente?"
        End Select
        If Environment.OSVersion.Version.Major = 10 Then
            Text = ""
            Win10Title.Visible = True
        End If
        Win10Title.BackColor = CurrentTheme.BackgroundColor
        BackColor = CurrentTheme.SectionBackgroundColor
        ForeColor = CurrentTheme.ForegroundColor
        ListView1.BackColor = CurrentTheme.SectionBackgroundColor
        ListView1.ForeColor = ForeColor
        MainForm.ViewPackageDirectoryToolStripMenuItem.Image = GetGlyphResource("openfile")
        Dim handle As IntPtr = MainForm.GetWindowHandle(Me)
        If MainForm.IsWindowsVersionOrGreater(10, 0, 18362) Then MainForm.EnableDarkTitleBar(handle, CurrentTheme.IsDark)
    End Sub

    Private Sub ListView1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListView1.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            Dim item As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
            If item IsNot Nothing Then
                MainForm.AppxPackagePopupCMS.Show(sender, e.Location)
            End If
        End If
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems.Count = 1 Then
            MainForm.ResViewTSMI.Visible = True
            DynaLog.LogMessage("Updating context menu items...")
            Try
                Select Case MainForm.Language
                    Case 0
                        Select Case My.Computer.Info.InstalledUICulture.ThreeLetterWindowsLanguageName
                            Case "ENU", "ENG"
                                MainForm.ResViewTSMI.Text = "View resources of " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                            Case "ESN"
                                MainForm.ResViewTSMI.Text = "Ver recursos de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                            Case "FRA"
                                MainForm.ResViewTSMI.Text = "Voir les ressources de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                            Case "PTB", "PTG"
                                MainForm.ResViewTSMI.Text = "Ver recursos de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                            Case "ITA"
                                MainForm.ResViewTSMI.Text = "Visualizza le risorse di " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                        End Select
                    Case 1
                        MainForm.ResViewTSMI.Text = "View resources of " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                    Case 2
                        MainForm.ResViewTSMI.Text = "Ver recursos de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                    Case 3
                        MainForm.ResViewTSMI.Text = "Voir les ressources de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                    Case 4
                        MainForm.ResViewTSMI.Text = "Ver recursos de " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                    Case 5
                        MainForm.ResViewTSMI.Text = "Visualizza le risorse di " & If(MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()).ToString().StartsWith("ms-resource:", StringComparison.OrdinalIgnoreCase), ListView1.FocusedItem.SubItems(1).Text, MainForm.GetPackageDisplayName(ListView1.FocusedItem.SubItems(0).Text, ListView1.FocusedItem.SubItems(1).Text.Replace(" (Cortana)", "").Trim()))
                End Select
            Catch ex As Exception
                MainForm.ResViewTSMI.Text = ""
                MainForm.ResViewTSMI.Visible = False
            End Try
        End If
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        HelpBrowserForm.WebBrowser1.Navigate(Application.StartupPath & "\docs\img_tasks\appx\remove_provisionedappxpackage\index.html#questions")
        HelpBrowserForm.MinimizeBox = False
        HelpBrowserForm.MaximizeBox = False
        HelpBrowserForm.ShowDialog()
    End Sub
End Class
